package com.henushang.ranking.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.henushang.ranking.constant.FieldConstant;
import com.henushang.ranking.dao.CategoryInfoDao;
import com.henushang.ranking.domain.CategoryInfo;
import com.henushang.ranking.service.CategoryService;
import com.mongodb.client.model.Sorts;

@Service("categoryService")
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryInfoDao categoryInfoDao;

    @Override
    public List<CategoryInfo> getNavCategory() {

        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put(FieldConstant.status, 1);
        return categoryInfoDao.findListAndSort(queryMap, Sorts.descending("weight"));
    }

    @Override
    public CategoryInfo getById(String id) {
        return categoryInfoDao.getOne(id);
    }

    @Override
    public List<CategoryInfo> getCategoryList(Map<String, Object> queryMap) {
        if (!queryMap.containsKey(FieldConstant.status)) {
            queryMap.put(FieldConstant.status, 1);
        }
        List<CategoryInfo> list = categoryInfoDao.getListByQueryMap(queryMap);

        return list;
    }
}
